Creating a cms system example in php and MySQL web development ( original book edition )?

107 2

A problem occurred while executing the index. Php file, the database has been created.
Error tip:

Warning: [:: ]: ( hy000/2003 ): can 't connect to mysql server on 'localhost '( 10061 ) in D:apmxehtdocs28db_fns.php on line 5

Warning: [:: query ( ) ]: couldn & t in D:apmxehtdocs28index.php on line 8

Fatal error: call to a member function fetch_assoc ( ) on a non-object in D:apmxehtdocs28index.php on line 12

Development environment: apm express

How do these problems solve.

Added: index. Php connection database part code.

$handle = db_connect();
 $pages_sql = 'select * from pages order by code';
 $pages_result = $handle->query($pages_sql);
 echo '<table border="0" width="400">';
 while ($pages = $pages_result->fetch_assoc()) 
 {
 $story_sql ="select * from stories
 where page = '{$pages['code']}'
 and published is not null
 order by published desc";
 $story_result = $handle->query($story_sql);
 if ($story_result->num_rows) 
 {
 $story = $story_result->fetch_assoc();
 echo"<tr>
 <td>
 <h2>{$pages['description']}</h2>
 <p>{$story['headline']}</p>
 <p align='right' class='morelink'>
 <a href='page.php?page={$pages['code']}'>
 Read more {$pages['code']}.. .
 </a>
 </p>
 </td>
 <td width='100'>";
/*db_connect函数功能*/
function db_connect()
{
 $handle = new mysqli('localhost', 'content', 'password', 'content'); 
 if (!$handle)
 {
 return false;
 }
 return $handle;
}

2 Answers

78 2

First make sure that all the parameters are correct when you construct the mysqli object, the four parameters are the address, user name, password, database name. In the database user name and password, you need to confirm that it's correct.

Then make sure that your database is up ( many people have forgotten ). Enter at the command line

telnet localhost 3306

See if you can connect.

...