Php fails to create a table, but no error is reported. Solution

Source: Internet
Author: User
Php fails to create a table, but no error is reported. solve PHPcode & lt ;? Php connection data $ conmysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot; welcome123 & quot;) ordie (& quot; unable to connect to database & quot ;. mysql_err php fails to create a table, but no error is reported.
PHP code
  
  

The page displays "no table", but the table should be created after the execution. I will refresh the page and still display "no table". can you please take a look at the Shenma problem?

------ Solution --------------------
Try:
PHP code
// Connect data $ con = mysql_connect ("localhost", "root", "welcome123") or die ("unable to connect to database ". mysql_error (); // Determine whether the my_project database $ existDB = mysql_select_db ("my_project", $ con); // echo "no my_project database"; if (! $ ExistDB) {// Create a DATABASE $ cdatabseSql = "Create DATABASE my_project"; mysql_query ($ cdatabseSql, $ con); mysql_select_db ("my_project", $ con ); // select database} else {echo "with database";} // Determine whether the sendmail table exists $ row = mysql_query ("show tables"); $ database = array (); $ finddatabase = "sendmail"; while ($ result = mysql_fetch_array ($ row, MYSQL_ASSOC) {$ database [] = $ result ['Tables _ in_test '];} unset ($ result, $ row); if (! In_array ($ finddatabase, $ database) {echo "no TABLE"; $ ctableSql = "Create TABLE sendmail (id int AUTO_INCREMENT primary key, tomail nvarchar (50 ), subject nvarchar (50), message text) "; mysql_query ($ ctableSql, $ con) ;}else {echo" ";}die ();
------ Solution --------------------
Try it like this,

PHP code
If (! $ ExistDB) {// Create a DATABASE $ cdatabseSql = "Create DATABASE my_project"; mysql_query ($ cdatabseSql, $ con); mysql_select_db ("my_project", $ con ); // add one sentence and select the database }............ // Determine whether the sendmail table exists $ row = mysql_list_tables ("my_project"); $ database = array (); $ finddatabase = "sendmail "; while ($ result = mysql_fetch_array ($ row) {$ database [] = $ result [0];} unset ($ result, $ row );

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.