| | |
MySQL efficiency
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hello,
I'm pretty new to PHP and MySQL. I was wondering what the most efficient way to access a large database would be. All the tutorials I've seen show something along the lines of:
But it seems to me that if 'table' was a large database then the time that it would take to copy 'table' into $database would grow fast. Wouldn't it be faster to only load a few rows if we knew their primary key?
And how do you look up a row by its primary key? What I found on Google didn't have much information with it explaining what was going on. Thanks!
I'm pretty new to PHP and MySQL. I was wondering what the most efficient way to access a large database would be. All the tutorials I've seen show something along the lines of:
$database = mysql_query("SELECT * FROM table"); But it seems to me that if 'table' was a large database then the time that it would take to copy 'table' into $database would grow fast. Wouldn't it be faster to only load a few rows if we knew their primary key?
And how do you look up a row by its primary key? What I found on Google didn't have much information with it explaining what was going on. Thanks!
Last edited by peter_budo; Mar 31st, 2009 at 3:39 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
table is the name of the table in the database. $database in your example will contain a result set of rows from the database according to the query passed into the mysql_query function. It should probably be named $result instead of $database to give you a clearer understanding of what is happening.Try to think of a database being like a filing cabinet. The tables in the database are the files in the filing cabinet and store the actual data.
EDIT: To actually connect to the database in php, check out the mysql_connect function. Once connected you run SQL queries using the mysql_query function and interrogate the result with the mysql_fetch_* functions.
Last edited by darkagn; Mar 31st, 2009 at 1:04 am.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. Thanks darkagn. I guess a better way to phrase my question would be is it possible to only select one row at a time based on something like the primary key? Something along the lines of:
PHP Syntax (Toggle Plain Text)
$result = mysql_query("SELECT primaryKey FROM table");
php Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM table where id=%s, $id");
Last edited by almostbob; Mar 31st, 2009 at 7:04 pm.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
•
•
Join Date: Jan 2009
Posts: 33
Reputation:
Solved Threads: 1
your question is rather vague, if you're asking how to limit the results by a condition then almostbob asked your question.
If you meant columns by 'rows' then u asked the question yourself by:
but If you want efficiency, meaning finding something fast in a database, well, I guess very few people had trouble with this, and I think you don't have to worry about efficiency in this case.
If you meant columns by 'rows' then u asked the question yourself by:
$result = mysql_query("SELECT column FROM table"); but If you want efficiency, meaning finding something fast in a database, well, I guess very few people had trouble with this, and I think you don't have to worry about efficiency in this case.
Last edited by peter_budo; Apr 1st, 2009 at 4:39 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Similar Threads
- Resetting Auto Increment in MYSQL (PHP)
- Senior Web Solutions Developer (ColdFusion, Javascript, mySQL, HTML, CSS & XML Tools) (Web Development Job Offers)
- Inserting MySQL Data with PHP o_O (PHP)
- Newbie to Forum and IT (IT Professionals' Lounge)
- Looking for: C++ Software Developer - Center of Amsterdam (Software Development Job Offers)
- Large website language? (IT Professionals' Lounge)
- Working in Visual C++ to parse some text files (C++)
- [HIRING] full-time PHP Ninja (work from anywhere) (Software Development Job Offers)
Other Threads in the PHP Forum
- Previous Thread: Cookies and session are not working on my server for the index page
- Next Thread: Search Multiple Fields in Query - help
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






