bookmark - How To Use MySQL, PHP And Recordsets ? Using info retrieved from MySQL via PHP

How To Use MySQL, PHP And Recordsets ? - Using info retrieved from MySQL via PHP

 
 Discussion by hellonull with 9 Replies.
 Last Update: October 27, 2005, 9:58 pm
 
bookmark - How To Use MySQL, PHP And Recordsets ? Using info retrieved from MySQL via PHP  
    
free web hosting
 
I am just beginning to use PHP and MySQL together. I was wondering, in PHP, how do you access information you have retrieved from a MySQL database? I've used ASP with an MS Access database before, and in that scenario the information returned through an SQL query can be stored in a recordset. Basically, I am wanting to know how to do this in PHP.

Thu Oct 14, 2004    Reply    New Discussion   


hmmm I think you're wanting to know how yo can access you're mysql files? well I'm gunna have to say from expirence on other servers that you just go into phpmy admin but meh it could be different...I'll let you know when I learn mroe about the hosting on this website

Thu Oct 14, 2004    Reply    New Discussion   

Thanks lhunath. Your reply is just what I was looking for, getting results from the query and then extracting data from a specific "cell" (as it would appear in Access). I've implemented what you've said into my code and I am able to get the desired results now. Thanks again.

Thu Oct 14, 2004    Reply    New Discussion   

There are lot's of handy functions in PHP to be used with MySQL. I strongly recommend glancing through this page http://www.php.net/manual/en/ref.mysql.php

There are lots of stuff that can make your life easier. I remember when I started using PHP & MySQL combo, I stubbornly programmed lots of stuff myself, when I didn't know of all things that were just function call away.

So it is a good idea to check the manual to know roughly what kind of features are available. When you program something, instead of implementing it yourself, it might come to your mind that there could be a ready function for this.

Fri Oct 15, 2004    Reply    New Discussion   


I went to the manual but I am not able to find the function that moves the value of a variable to the next item in an array of MySQL query results. What would be the function (I'm pretty sure that there is one for something like this) and how would I use it? Or, simply put, what is the PHP equivalent of ASP's RS.MoveNext function?

Fri Oct 15, 2004    Reply    New Discussion   

I'm not exactly sure what you want to do. But what I know is, that PHP does not really have that many functions to use MySQL directly. They like you better to use mysql_query() and then the MySQL code in it. Makes it easier for you since you already know mysql. If you don't know that command, try finding out what the ASP-function actually does! Look on the bright side you don't have to learn it new completely.. :-)

Thu Oct 27, 2005    Reply    New Discussion   

QUOTE (ruben)

I'm not exactly sure what you want to do. But what I know is, that PHP does not really have that many functions to use MySQL directly. They like you better to use mysql_query() and then the MySQL code in it. Makes it easier for you since you already know mysql. If you don't know that command, try finding out what the ASP-function actually does! Look on the bright side you don't have to learn it new completely.. :-)

Actually PHP has about 31 functions for just the MySQL:

QUOTE

mysql_affected_rows (get the number of affected rows in the pervious MySQL operation),
mysql_close (close a MySQL connection),
mysql_connect (open a connection to MySQL server),
mysql_create_db ( create a MySQL database),
mysql_data_seek (mover the internal result pointer),
mysql_db_query (Send an SQ: query to MySQL),
mysql_drop_db (Drop a MySQL database),
mysql_return_errno (Returns the error number of the pervious MySQL operation),
mysql_error (Returns the text of the error message from the previous MySql operation),
mysql_fetch_array (Fetches a result row as an associative array),
mysql_fetch_field (Get column information from a result and return it as an object),
mysql_fetch_length (Gets the maximum data size of each column in a result),
mysql_fetch_object (Fetches a result row ans an object),
mysql_fetch_row (Get a result row as an enumerated array),
mysql_field_flags (Gets the flags associate with the specified field in a result),
mysql_field_len (Returns the length of a  specified field),
mysql_field_name (Get the name of the specified field in a result),
mysql_field_seek (Set the pointer to a specific field offset),
mysql_field_table (Get the name of the table the specified field is in),
mysql_field_type (Get the type of the specified field in a result),
mysql_free_result (free result memory),
mysql_insert_id (Get the ID generated from the previous INSERT operation),
mysql_list_dbs (Lists the databases available on a MySQL server),
mysql_list_fields (List MySQL result fields),
mysql_list_tables (Lists the tables in a MySQL database),
mysql_num_fields (Get the number of fields in a result),
mysql_num_rows (Get the number of rows in a result),
mysql_pconnect (Open a persistent connection to a MySQL database server),
mysql_query (Send anSQL query to MySQL),
mysql_result (Get result data)and of course
mysql_select_db (Select a MySQL database)


Plus for mSQL there are 28, for Oracle there are 40, forPostgreSQL there are 32, and there is Sybase, InterBase with 11, and several with Informix and Hyperwave... I could have made un unordered list but I used that format to save space in the post and not have a long list of PHP functions.

Thu Oct 27, 2005    Reply    New Discussion   

There are a lot of good tutorials which can be easily found by using google how to start using mysql+php being a newbie which explains everything better and more clear than the php.net manual, so I would recommend to take 1 minute to find one and read it.

Thu Oct 27, 2005    Reply    New Discussion   

Yes man, but if you would make the effort and read through the descriptions on php.net then you could easily find a lot of notes saying "pleae use mysql-code blahblahblah instead".
If you are new to MySQL then you are better off using MySQL code in mysql_query, that's what I was trying to say.

Thu Oct 27, 2005    Reply    New Discussion   

You'll need to use queries for that.

CODE

$q = mysql_query("SELECT $columns FROM $table")

$q will be a MySQL query result. To get the data from it use something like this:

CODE

$qRow = mysql_fetch_array($q);

$qRow will contain one row of the MySQL query. It will be in the form of an associative array. For example, if you have a table like this:
NAME | ADDRESS

John | MyStreetRox 89
Pete | MyStreetRoxMore 12

then your $qRow will contain the array with as key: [Name] and as value "John". And as key [Address] and as value "MyStreetRox89"

Good Luck

( echo $qRow["Name"]; will give you John )

Thu Oct 14, 2004    Reply    New Discussion   

Quickly Post to How To Use MySQL, PHP And Recordsets ? Using info retrieved from MySQL via PHP w/o signup Share Info about How To Use MySQL, PHP And Recordsets ? Using info retrieved from MySQL via PHP using Facebook, Twitter etc. email your friend about How To Use MySQL, PHP And Recordsets ? Using info retrieved from MySQL via PHP Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Data Warehouse   Data Warehouse (0) (2) Access To MySQL Remotely   Access To MySQL Remotely