I am new in php and reading book "PHP Bible". I wanted to code an example. The example is following. I have a database with 2 tables. The first table is country and the second is city. The country table hase the following columns:
id, continent and name
The city table has the following columns:
id, countryId and name.
Now I would like to run the following query against the database:
select country.continent, country.name, city.name from country, city where country.id=city.countryId
The code I wrote so far is:
<?php
$conn=mysqli_connect("127.0.0.1", "root", "123","example1");
- this establishes the connection with the database it works fine
$query="select country.continent, country.name, city.name from country, city where country.id=city.countryId ";
$result=mysqli_query( $conn, $query);
if(!$result)
die("could not fetch the data");
Ideally the following table must be printed:
print("<table border=1>\n");
while($row=mysqli_fetch_row($result))
{
print("<tr>");
for($col=0; $col<3;$col++)
print("<td>$row[$col]</td>\n");
print("</tr>");
}
print("</table>\n");
However,
Could not fetch data
message is printed.
When I use only one table, say country or city everything works fine. The trouble occurs when I try to use both tables. The error.log file gives the following error:
HP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/msql.so' - /usr/lib/php5/20121212/msql.so: cannot open shared object file: No such file or directory in Unknown on line 0
What should I do to make code work? Why 1 table code works but does not work when I use 2 tables? Thanks in advance