tailieunhanh - Sams Teach Yourself PHP, MySQL and Apache in 24 Hours phần 4
Báo cáo Thiết kế I-Khóa học này kéo dài hai ngày được thiết kế cho người mới bắt đầu Crystal Reports có nhu cầu để nhanh chóng trở nên thành thạo trong việc tạo ra và sửa đổi các báo cáo. Một số trong những chủ đề bao gồm lập kế hoạch cho một báo cáo, tạo ra một báo cáo cơ bản, hồ sơ lựa chọn, phân loại | Because the mysql_query function only returns a true or false result the boring output of this script is 1 The 1 equals true and indicates that the query was successfully executed. A 0 would have indicated failure. Access MySQL through the command-line interface to verify the creation of the testTable table mysql describe testTable - Field Type - Null Key Default Extra - id testField int 11 varchar 75 - YES PRI NULL NULL auto_increment - - 2 rows in set sec Congratulations you have successfully created a table in your MySQL database using PHP Retrieving Error Messages Take some time to familiarize yourself with the mysql_error function as it will become your friend. When used in conjunction with the PHP die function which simply exits the script at the point at which it appears the mysql_error function will return a helpful error message when you make a mistake. For example now that you have created a table called testTable you won t be able to execute that script again without an error. Let s try to execute the script again but modify it first to utilize the mysql_error function see Listing . Listing The Script to Create a Table with Error Messages 1 php 2 open the connection 3 conn mysql_connect localhost joeuser somepass 4 pick the database to use 5 mysql_select_db testDB conn 6 create the SQL statement 7 sql CREATE TABLE testTable id int not null primary key auto_i 8 testField varchar 75 9 execute the SQL statement 10 result mysql_query sql conn or die mysql_error 11 echo the result identifier 12 echo result 13 When you execute the script you should see something like the following in your Web browser Table testTable already exists How exciting Move on to the next section to start inserting data into your table and soon you ll be retrieving and formatting it via PHP. Team LiB PREVIOUS Team LiB Working with MySQL Data Inserting updating deleting and retrieving data all revolve around the use of the mysql_query function to execute the basic SQL .
đang nạp các trang xem trước