| very simple mysql connection from php |
|
| programming |
|
This article describes how to connect to a mysql database from a php script. It is realy the most simple way of using mysql databases in php, no fancy wrapper classes, no functions and NO security! We will care about that later...
Step 1: Connect to the mysql server
The command to do that is "mysql_connect" and the return value is either a connection-id or FALSE.
example:
In this example the mysql server and the webserver are running on the same server (localhost).
Step 2: select a databaseThe command to do that is "mysql_select_db" and the return value is either TRUE or FALSE.
example:
Step 3: make a query
The command to make a query is "mysql_query" and the return value is either TRUE, FALSE or a resource id.
example:
Ok, but where is the result now? $result only contains a resource id and the command to read the real result is mysql_fetch_array(). mysql_fetch_array returns an array with the result from our query.
All together
Comments (0)
Powered by !JoomlaComment 4.0 beta1
!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved." |


