Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> How To Use MySQL, PHP And Recordsets ?, Using info retrieved from MySQL via PHP
hellonull
post Oct 14 2004, 08:37 PM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 6
Joined: 11-October 04
From: Detroit, MI, USA
Member No.: 1,108



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.

This post has been edited by microscopic^earthling: Oct 27 2005, 03:49 PM
Go to the top of the page
 
+Quote Post
spacewaste
post Oct 14 2004, 08:42 PM
Post #2


Premium Member
Group Icon

Group: Members
Posts: 385
Joined: 13-October 04
From: Ontario
Member No.: 1,175



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
Go to the top of the page
 
+Quote Post
lhunath
post Oct 14 2004, 08:45 PM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 224
Joined: 13-October 04
From: Belgium
Member No.: 1,160



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 )
Go to the top of the page
 
+Quote Post
hellonull
post Oct 14 2004, 09:00 PM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 6
Joined: 11-October 04
From: Detroit, MI, USA
Member No.: 1,108



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.
Go to the top of the page
 
+Quote Post
Hercco
post Oct 15 2004, 10:52 AM
Post #5


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228



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.

Go to the top of the page
 
+Quote Post
hellonull
post Oct 15 2004, 07:03 PM
Post #6


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 6
Joined: 11-October 04
From: Detroit, MI, USA
Member No.: 1,108



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?
Go to the top of the page
 
+Quote Post
ruben
post Oct 27 2005, 02:25 PM
Post #7


Wheeeeeeee!
Group Icon

Group: Members
Posts: 245
Joined: 19-October 05
From: DG, Belgium
Member No.: 9,200



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.. :-)
Go to the top of the page
 
+Quote Post
Houdini
post Oct 27 2005, 03:37 PM
Post #8


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340



QUOTE(ruben @ Oct 27 2005, 09:25 AM)
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.

This post has been edited by jipman: Oct 27 2005, 04:51 PM
Go to the top of the page
 
+Quote Post
Quatrux
post Oct 27 2005, 04:14 PM
Post #9


the Q
Group Icon

Group: [HOSTED]
Posts: 1,094
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059
myCENTs:70.96



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.
Go to the top of the page
 
+Quote Post
ruben
post Oct 27 2005, 09:58 PM
Post #10


Wheeeeeeee!
Group Icon

Group: Members
Posts: 245
Joined: 19-October 05
From: DG, Belgium
Member No.: 9,200



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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL - Trouble With Bulk Insert Statements(3)
  2. MySQL Realtime Replication(4)
  3. Recover Tables From A MySQL .frm File(8)
  4. Mirror My MySQL Database To Another Mysql Server(4)
  5. How To Connect MySQL With Flash?(8)
  6. MySQL Output Database Question(18)
  7. MySQL, Multiple Tables(24)
  8. Navcat For MySQL(9)
  9. Permission Problem With Mysql Database Creation(8)
  10. Mysql And Php(15)
  11. Login System Using A Mysql Db(5)
  12. Oracle Vs. Mysql Vs. Postgresql(9)
  13. Subqueries In Mysql(1)
  14. Apache Php With Mysql On Windows [solved](9)
  15. Not Understanding Mysql(4)
  1. Mysql - So Hard(14)
  2. Mysql Problem(1)
  3. Sun Bought Mysql(6)
  4. Mysql Backup With Another Address?(4)
  5. I Have An Error With My Mysql Connection(7)
  6. Mysql And User File_priv(0)
  7. Mysql Database Management(1)
  8. Mysql Database Entry By Excel Sheets(2)
  9. Mysql On Computer(9)
  10. Any Website Provide Free Host Mysql Host?(4)
  11. Mysql Multiple Tables(1)
  12. Mysql Overhead(3)
  13. Login System(6)


 



- Lo-Fi Version Time is now: 21st November 2008 - 12:03 AM