Did you know FaceySpacey is the creator of Redux-First Router and Universal?

The Startup Incubator.
Your one stop social media shop
Resource Categories:

Technical
Non-Technical
Refer A Friend
Popular Articles
DEVELOPMENT TOOLS 1 - VERSION CONTROL (Mercurial)
CONTRACTING 2 - TOP 10 EASY SITE CREATOR TOOLS
Subscribe
MySQL 2 - MYSQL & PHP
This tutorial will describe how to get MySQL data into PHP at the most basic level. You will use built-in PHP functions designed specifically for talking to your MySQL application. When I was first learning this, the hard part for me to get was how MySQL and PHP connect to each other. The idea is simply that both are applications on your server, and one application can talk to the other. And PHP specifically made ways to talk to php, i.e. through functions.
$username="username"; $password="password"; $database="your_database"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM user"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); echo "$first $last"; $i++; }
specifically So what this code is doing is:
1) logging into your MySQL application via the PHP mysql_connect() function.
2) then selecting the database to use via the mysql_select_db() function
3) and then executing a SELECT query to grab all users from the database via the mysql_query() function.
One thing to point out here is that the SELECT statement SELECT * FROM user is grabbing multiple rows, unlike what you saw in the last tutorial where we used a ‘WHERE’ statement to limit the result to one row. So accordingly we must loop through all the results and echo the first and last name of each user on their own lines.
We use the mysql_result() function to access part of the $result set via its row # stored in the $i variable. The while statement simply loops from 0 upwards until $i is not less than $num, which via the mysql_numrows() function equals the total of rows stored in the $result resource.
In short, the while statement loops through all the rows in the result set, assigning the first and last names to php variables, and then echoes out the full name to the browser.
The key thing to notice here as you progress to the next tutorial is that this is where the rubber meets the road between your PHP code and your MySQL code. Even if you do end up writing lots of SQL in your Yii applications, you won’t have to do all this tedious common coding with functions like mysql_result() etc. Yii will automate all that for you, so at most you just have to enter a slick a SQL statement, and at least you don’t type any SQL at all.
Comments

SMM 3 - FORMULA TO FIND INFLUENCERS