0

First of all i'm kind of a newbie to PHP and MySQL. My php script connected to database successfully but i have problem with executing query. Problem is that my script went normally until 'echo " A ";' and than stops. Script never reach line 'echo " B ";'.

My PHP code:

<?php
$servername = "****";
$username = "****";
$password = "****";
$db_name = "****";

// Create connection
$conn = mysqli_connect($servername, $username, $password ,$db_name);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

$sql = "SELECT * FROM street";

$result = $conn->query($sql);

if (!$result) {
    echo "DB Error, could not query the database\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
else{
    echo " A ";
    $row = mysql_fetch_assoc($result);
    echo " B ";
}?>

Maybe i has something to do with the ' * ' sign at the start of the line but im stucked with it

My Query to creation of table and nothing else was inserted.

CREATE TABLE point_of_interest.City(
Id serial PRIMARY KEY,
Id_country INT REFERENCES Country(id),
City_name VARCHAR (60) )

Also when i do SELECT COUNT(*) FROM street; it shows 0 rows at MySQL Workbench.

MySQL version 8.0

  • 1
    Don't mix two different API's – Rotimi Mar 25 '20 at 03:55
  • Note: The [object-oriented interface to `mysqli`](https://www.php.net/manual/en/mysqli.quickstart.connections.php) is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface where missing a single `i` can cause trouble. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era and should not be used in new code. You’re mixing the two styles here for no apparent reason and using the wrong API by accident. – tadman Mar 25 '20 at 03:59
  • Hint: `$result->fetch_assoc()` is all you need. – tadman Mar 25 '20 at 04:00

0 Answers0