BR
asked on
I have already a connection, I do not want to open another connection to execute to mysql query.
I have already a connection, I do not want to open another connection to execute to mysql query.
How can I rewrite the mysql script and php to execute the query?
// Create connection ( I already have one )
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//how can rewrite below code to execute the sql qurey without above connection script?
$sql = "SELECT isim FROM KullaniciBilgileri where uid='$uid'";
$result = $conn->query($sql);
// after successful connection and execution of sql I have this code below to write the results.
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["uid"]. " - İsim: " . $row["pwd"]. " " . $row["isim"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
How can I rewrite the mysql script and php to execute the query?
// Create connection ( I already have one )
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//how can rewrite below code to execute the sql qurey without above connection script?
$sql = "SELECT isim FROM KullaniciBilgileri where uid='$uid'";
$result = $conn->query($sql);
// after successful connection and execution of sql I have this code below to write the results.
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["uid"]. " - İsim: " . $row["pwd"]. " " . $row["isim"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
ASKER
I already did this, but it didn't work, because I use $conn variable in the if statement.
I think we should rewrite the if statement and the mysql sentence below
$sql = "SELECT isim FROM KullaniciBilgileri where uid='$uid'";
$result = $conn->query($sql);
// after successful connection and execution of sql I have this code below to write the results.
if ($result->num_rows > 0) {
I think we should rewrite the if statement and the mysql sentence below
$sql = "SELECT isim FROM KullaniciBilgileri where uid='$uid'";
$result = $conn->query($sql);
// after successful connection and execution of sql I have this code below to write the results.
if ($result->num_rows > 0) {
Every PHP script that connects to a MySQL database must have it's own connection code. Why do you want to do without it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you Olaf,
Just remove following code which connects to database:
Open in new window