gameboyz 0 Posted March 27, 2009 Report Share Posted March 27, 2009 HiExample for php you can code it in a .php file and the script will be converted into HTML and displayed on the browser. However how and when is SQL used? There isn't any .sql file is there? So when and how do you use the SQL language? Quote Link to post Share on other sites
Stefano 0 Posted March 27, 2009 Report Share Posted March 27, 2009 HiExample for php you can code it in a .php file and the script will be converted into HTML and displayed on the browser. However how and when is SQL used? There isn't any .sql file is there? So when and how do you use the SQL language?whenever you need to retrive or manipulate data stored in a database.Concerning on service based on server scripting (php), client scripting (js) and Db (MySQL, postgresql, Oracle,...) sql can code can be implemented in all of those parts.in javascript (very riskful for haking attack) to be passed to an asyncronus service;in the DB as stored procedure or trigger;in PHP to perorm operation on database according to request activity.Actually sql has not (usually) its own dedicated file, usually is inserted in the php code and passed as text string i.e. <?php$dbhost = 'host';$dbusername = 'root';$dbuserpassword = 'password';$default_dbname = 'database';function db_connect(){ global $dbhost, $dbusername, $dbuserpassword, $default_dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = "Connection failed to the host $dbhost."; return 0; } else if(empty($dbname) && !mysql_select_db($default_dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id;}$mysession=db_coonect; $query = "select * from my table"; THIS IS SQL CODE INSIDE A PHP STRING VAR, INSIDE PHP CODE, INSIDE A .PHP FILE $result = mysql_query($query, $mysession); while($query_data = mysql_fetch_row($result)) { echo query_data;}?> regardsstefano de boni Quote Link to post Share on other sites
gameboyz 0 Posted March 27, 2009 Author Report Share Posted March 27, 2009 So you mean that starting from http://www.w3schools.com/PHP/php_mysql_intro.asp all those are not PHP codes anymore but instead they're already SQL codes? Quote Link to post Share on other sites
Stefano 0 Posted March 27, 2009 Report Share Posted March 27, 2009 So you mean that starting from http://www.w3schools.com/PHP/php_mysql_intro.asp all those are not PHP codes anymore but instead they're already SQL codes?codes?! I didn't know "code" was a countable word, therefore I improve my english, be patient with my english please!In that page there is not any SQL code!!!you will find SQL codes in the next page nested inside PHP code.All functions starting with suffix mysql_ are still PHP function oriented to initialize the connection between PHP and MySQL. By doing that SQL codes can be passed, since then on, to MySQL server through by php string.if (mysql_query("CREATE DATABASE my_db",$con))if (mysql_query(" : this is PHPCREATE DATABASE my_db : this is SQL nested but "CREATE DATABASE my_db" (quoted) is actually a string",$con)) : this is PHP againthus I meanCREATE DATABASE my_db : this has nosense for PHP!!!but "CREATE DATABASE my_db" : this for PHP has sense as string to be passed to someone who knows what to do with.still CREATE DATABASE my_db : this has sense for MySQL and is qhat recive from PHP library module.regardsregards Quote Link to post Share on other sites
Synook 47 Posted March 27, 2009 Report Share Posted March 27, 2009 Simple answer - you use the mysql_query() function inside your PHP code. ?http://www.php.net/manual/en/function.mysql-query.php Quote Link to post Share on other sites
Stefano 0 Posted March 27, 2009 Report Share Posted March 27, 2009 Simple answer - you use the mysql_query() function inside your PHP code. ?Actually mysql_query() is a "PHP" function, there's no way to use it outside PHP.better answer:mysql_query() is the mean through which instructions are passed to MYSQL.regards Quote Link to post Share on other sites
justsomeguy 1,135 Posted March 27, 2009 Report Share Posted March 27, 2009 codes?! I didn't know "code" was a countable word, therefore I improve my englishDon't get too far, I never say "codes". The only person I've heard say that when I was talking to them was a 14 year old girl (no offense).So you mean that starting from http://www.w3schools.com/PHP/php_mysql_intro.asp all those are not PHP codes anymore but instead they're already SQL codes?To put it another way, PHP cannot understand SQL code, and the MySQL database cannot understand PHP code, but they can communicate with each other. The functions like mysql_connect and mysql_query are what they use to communicate. You can use PHP to send SQL code to a MySQL database using mysql_query, and the database will execute the code and give PHP back the results. Quote Link to post Share on other sites
Stefano 0 Posted March 28, 2009 Report Share Posted March 28, 2009 Don't get too far, I never say "codes". The only person I've heard say that when I was talking to them was a 14 year old girl (no offense).don't worry, is very long time I left England, and it's very long time I don't use the noble language, so really, I was sure code was an uncountable noun and I was really surprised when I read "codes", not too an ironic commentTo put it another way, PHP cannot understand SQL code, and the MySQL database cannot understand PHP code, but they can communicate with each other. The functions like mysql_connect and mysql_query are what they use to communicate. You can use PHP to send SQL code to a MySQL database using mysql_query, and the database will execute the code and give PHP back the results.That's right!!! Quote Link to post Share on other sites
Synook 47 Posted March 29, 2009 Report Share Posted March 29, 2009 Actually mysql_query() is a "PHP" function, there's no way to use it outside PHP.better answer:mysql_query() is the mean through which instructions are passed to MYSQL.regardsThat's why you have to use it inside your PHP code... Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.