Edit
Easy Manual Installation and
Basic Usage of PurePHP MySQL
API
Data Definition Statements and
the PurePHP MySQL API
Data Manipulation Statements
and the PurePHP MySQL API
Using the PurePHP MySQL API
Result Set
Administrative and Utility
Statements with the PurePerl
MySQL API
Column Properties with the
PurePHP MySQL API
Locking a Table and Ending a
Session with the PurePHP MySQL
API
Quæe@@"M{SYÍ @0%xeru&
dmentr<«a>¼/p|Per%ZHX!MySQL MulTi¬CðapeygnvtjÐ2i` Ct?z%l Prncáäur'¼/a|<p¾,p glñqs'nav'(rVùdd=''^<áhref=' u2JPS-my×QL-Tr`N÷åsäko,nhtL'>PurePHP"MqSSÈ8E2-fccctiOn¼?a>/p.<2(cHecq='nav'0s4ám%ãggŸá8+rEF½·Sompressed-AtÀ5VAhues-wmtx-t`d-PurePXPmEqSqH-ACMâ1vm>CkmhpEg{#L8GqVaàFaMums€si6h8jbphe"Q}÷epHÐ0MySqLàQPh
sä0z%o='CoepRa{óE`oSqLCtateoefesmith-the-PuReÄX 'MySQL-PIhtm'>C/mpEs’udSQL Ct!|ements!wíth
the PupeXIQ É}SAN aPÉ,'i¯p®|pCchqsS=¯|Ez7"÷uyèe='/:u"href='SSL-Anä=TLÓ-7+tH-òim¨XuVa@JP-MySSL%@PI.hty'nYSL qn$(TLS wie`d\|'`XuzmplT=p¤k,AwR='jaf%$sd{le=§%>v` hre&='asýnf(æmoñR-Replicaði.5w zh%uig©XtòeP
P-My[Ql)API.h~m;Acy.khron/uqZlqlècå:y^,¨g{vj
Bacod!å¥Íém ar¼/a|ð:X6q ãla1s5"New"º¼/Q|‰<2 clas{=Âka‘"6A'òeD/%lt>a~5?t~H Foreword: In this part of the series, I show you how data definition statements can be used with the PurePHP MySQL API. By: Chrysanthus Date Published: 17 Jan 2018Data Definition Statements and the PurePHP MySQL API
Using the PurePHP MySQL API – Part 2
Introduction
Examples of Data Definition Statements
There are many data definition statements. I will use only the CREATE DATABASE and CREATE TABLE statements here. I will use these statements to create the database, PetStore and its table. You use the other data definition statements in the same way as I use these two: as the query() function argument. You should try all the code samples of this series.
The query() Function Syntax
The query function syntax is:
Boolean query("SQLstr");
You type a semicolon at the end of the query() function call and not at the end of the SQL statement. The SQL statement is typed in quotes without the ending semicolon. The function returns and nothing else, if it succeeds or false and nothing else if it fails. Any positive message developed is got from the variable, Message accessible from your script as, $Message . Any error message is got by accessing $Error_msg (from your script).
The following code segment will create a database, if connection has been accepted:
$crdb = "create database PetStore";
if (query($crdb) !== true)
{
echo $Error_msg, "<br>";
}
else
{
#select and use database
}
After creating the database, you can select it with the following code segment:
if (!select_db("PetStore"))
{
echo $Error_msg, "<br>";
}
else
{
#Statements to create tables and use the database can go here.
}
After selecting the database, you can go on to create tables. The following code segment creates a table:
$crtbl = "CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE)";
if (!query($crtbl))
{
echo $Error_msg, "<br>";
}
else
{
#you can insert rows here.
}
Now, the next time you want to use this same database, you do not have to create it again. You simply select it.
That is it for this part of the series. In the next part of the series, we do data manipulation
ChrysRelated Links
Pure PHP Mailsend - sendmail
PurePHP MySQL API
Using the PurePHP MySQL API
More Related Links
Basics of PHP with Security Considerations
cousins
Using the EMySQL API
Using the PurePerl MySQL API
BACK NEXT