{"id":3682,"date":"2015-06-25T04:43:20","date_gmt":"2015-06-24T23:13:20","guid":{"rendered":"http:\/\/cmscomputer.in\/blog\/?p=3682"},"modified":"2015-07-03T19:52:02","modified_gmt":"2015-07-03T14:22:02","slug":"learn-php-basics-for-freshers-and-experienced","status":"publish","type":"post","link":"https:\/\/www.cmscomputer.in\/blog\/learn-php-basics-for-freshers-and-experienced\/","title":{"rendered":"Learn PHP Basics &#8211; For Freshers and Experienced"},"content":{"rendered":"<h3 style=\"color: #dd3333;\">Database Connection<\/h3>\n<h5>Connect mysqli with php using Object-Oriented Way.<\/h5>\n<p><code>$host = \"localhost\";<br \/>\n$username = \"root\";<br \/>\n$password = \"\";<br \/>\n$conn = new mysqli($host, $username, $password);<br \/>\n\/\/connect to server<br \/>\nif ($conn-&gt;connect_error) {<br \/>\ndie(\"Connection failed: \" . $conn-&gt;connect_error);<br \/>\n}<br \/>\necho \"Connected successfully\";<\/code><\/p>\n<h5>Connect mysqli with php using Procedural Way.<\/h5>\n<p><code>$host = \"localhost\";<br \/>\n$username = \"root\";<br \/>\n$password = \"\";<br \/>\n$dbname = \"cmscomputer\";<br \/>\n\/\/ Create connection<br \/>\n$conn = mysqli_connect($host, $username, $password, $dbname);<br \/>\n\/\/ Check connection<br \/>\nif (!$conn) {<br \/>\ndie(\"Connection failed: \" . mysqli_connect_error());<br \/>\n}<br \/>\necho \"Connected successfully\";<br \/>\n?&gt;<br \/>\n<\/code><\/p>\n<h5>Connect mysqli with php using PDO.<\/h5>\n<p><code>$host = \"localhost\";<br \/>\n$username = \"root\";<br \/>\n$password = \"\";<br \/>\n$conn = new PDO(\"mysql:host=$host;dbname=myDB\", $username, $password);<br \/>\n\/\/ set the PDO error mode to exception<br \/>\n$conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);<br \/>\necho \"Connected successfully\";<\/code><\/p>\n<h3 style=\"color: #dd3333;\">convert string to uppercase in php<\/h3>\n<p><code>$string=\"cms computer training center\";<br \/>\necho strtoupper($string);<\/code><\/p>\n<h3 style=\"color: #dd3333;\">convert string to lowercase in php<\/h3>\n<p><code>$string=\"CMS COMPUTER TRAINING CENTER\";<br \/>\necho strtolower($string);<\/code><\/p>\n<h3 style=\"color: #dd3333;\">convert first letter of string to uppercase in php<\/h3>\n<p><code>$string=\"cakephp and zend\";<br \/>\necho ucwords($string);<\/code><\/p>\n<h3 style=\"color: #dd3333;\">delete a php file from server<\/h3>\n<p><code>$file=\"full_path\/filename.php\"<br \/>\nunlink($file); \/\/make sure you have enough permission to do delete the file.<\/code><\/p>\n<h3 style=\"color: #dd3333;\">convert array to json in php<\/h3>\n<p><code>$array = array('one','two');<br \/>\necho json_encode($array); \/\/use json_decode for decode<\/code><\/p>\n<h3 style=\"color: #dd3333;\">serialize an array in php<\/h3>\n<p><code>$array = array('php','mysql');<br \/>\necho serialize($array);\/\/use unserialize for convert serialized string to array<\/code><\/p>\n<h3 style=\"color: #dd3333;\">get ip address in php<\/h3>\n<p><code>$_SERVER['HTTP_USER_AGENT']<\/code><\/p>\n<h3 style=\"color: #dd3333;\">count the number of elements in an array<\/h3>\n<p><code>$array = array('html','css');<br \/>\nsizeof($array);<br \/>\ncount($array);<\/code><\/p>\n<h3 style=\"color: #dd3333;\">SESSION and SESSION Properties and Functions.<\/h3>\n<p>A session is a logical object enabling us to preserve temporary data across multiple PHP pages.<\/p>\n<p>1. Use function <code>session_start()<\/code> to initiate a session.<br \/>\n2. It is possible to propagate a session id via cookies or URL parameters.<br \/>\n3. Sessions automatically ends when the PHP script finishes executing, but can be manually ended using the <code>session_write_close()<\/code>.<br \/>\n4. The <code>session_unregister()<\/code> function unregister a global variable from the current session and the <code>session_unset()<\/code> function free all session variables.<br \/>\n5. To destroy all data registered in a session use function <code>session_destroy()<\/code>;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Database Connection Connect mysqli with php using Object-Oriented Way. $host = &#8220;localhost&#8221;; $username = &#8220;root&#8221;; $password = &#8220;&#8221;; $conn = new mysqli($host, $username, $password); \/\/connect to server if ($conn-&gt;connect_error) { die(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error); } echo &#8220;Connected successfully&#8221;; Connect mysqli with php using Procedural Way. $host = &#8220;localhost&#8221;; $username<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_joinchat":[],"footnotes":""},"categories":[1,7],"tags":[],"class_list":["post-3682","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-web-technologies"],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/posts\/3682"}],"collection":[{"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/comments?post=3682"}],"version-history":[{"count":8,"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/posts\/3682\/revisions"}],"predecessor-version":[{"id":3968,"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/posts\/3682\/revisions\/3968"}],"wp:attachment":[{"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/media?parent=3682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/categories?post=3682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmscomputer.in\/blog\/wp-json\/wp\/v2\/tags?post=3682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}