"PHP and MySQL Web development (the third edition of the original book)" To create a CMS system example of MySQL error problem?

Source: Internet
Author: User
Tags apm

A problem occurred while executing the index.php file, the database is already established.
Error message:

Warning:mysqli::mysqli () [Mysqli.mysqli]: (hy000/2003): Can ' t connect to MySQL server on ' localhost ' (10061) in D:\apmxe\ Htdocs\28\db_fns.php on line 5

Warning:mysqli::query () [Mysqli.query]: couldn ' t fetch mysqli in D:\apmxe\htdocs\28\index.php on line 8

Fatal Error:call to a member function Fetch_assoc () on a non-object in D:\apmxe\htdocs\28\index.php on line 12

Development environment: APM Express

May I ask how these problems can be solved?

Add: index.php Connection Database Part code

$handle = Db_connect ();  $pages _sql = ' SELECT * from pages order by code ';  $pages _result = $handle->query ($pages _sql); Echo '
 
 
  
  '; while ($pages = $pages _result->fetch_assoc ()) {$story _sql = ' SELECT * from stories where page =       ' {$pages [' Code '} ' and published is not NULL for ORDER by published Desc ";        $story _result = $handle->query ($story _sql);      if ($story _result->num_rows) {$story = $story _result->fetch_assoc (); echo "
  
  

{$pages [' description ']}

{$story [' headline ']}

Read more {$pages [' Code ']} ...

";
/*db_connect function function */function db_connect () {   $handle = new mysqli (' localhost ', ' content ', ' password ', ' content ');    if (! $handle)   {     return false;   }   return $handle;}

Reply content:

A problem occurred while executing the index.php file, the database is already established.
Error message:

Warning:mysqli::mysqli () [Mysqli.mysqli]: (hy000/2003): Can ' t connect to MySQL server on ' localhost ' (10061) in D:\apmxe\ Htdocs\28\db_fns.php on line 5

Warning:mysqli::query () [Mysqli.query]: couldn ' t fetch mysqli in D:\apmxe\htdocs\28\index.php on line 8

Fatal Error:call to a member function Fetch_assoc () on a non-object in D:\apmxe\htdocs\28\index.php on line 12

Development environment: APM Express

May I ask how these problems can be solved?

Add: index.php Connection Database Part code

$handle = Db_connect ();  $pages _sql = ' SELECT * from pages order by code ';  $pages _result = $handle->query ($pages _sql); Echo '
      
      
       
       '; while ($pages = $pages _result->fetch_assoc ()) {$story _sql = ' SELECT * from stories where page =       ' {$pages [' Code '} ' and published is not NULL for ORDER by published Desc ";        $story _result = $handle->query ($story _sql);      if ($story _result->num_rows) {$story = $story _result->fetch_assoc (); echo "
       
       

{$pages [' description ']}

{$story [' headline ']}

Read more {$pages [' Code ']} ...

/*db_connect function function */function db_connect () {$handle = new mysqli (' localhost ', ' Content ', ' password ', ' content '); if (! $handle) {return false; } return $handle;}

Mysqli The password of the link, the account is all right????

First confirm that when you construct the mysqli object, all parameters are correct, and the four parameters are the database address, user name, password, and database name . Where the database user name and password, you want to confirm whether the fill is correct.

Then confirm that your database is started (many people do forget). At the command line, enter

telnet localhost 3306 

To see if you can connect

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.