Home PHP
PHP variables in Javascript Print E-mail
Monday, 01 November 2010 16:09
It is easy to use the value of a PHP variable in Javascript:
 
<script language="javascript">
// $_GET["php_variable"] contains the string "hello Javascript";
var js_variable = "<?php echo $_GET["php_variable"]; ?>";
// and use the php value in javascript
alert(js_variable); // Shows hello Javascript
</script>
 
 
PHP MySQL STR_TO_DATE() Print E-mail
Tuesday, 26 October 2010 15:46
The SQL function STR_TO_DATE('01-12-1956', '%d-%c-%Y') converts the string '01-12-56' to the date 1956-12-01, the string can also be a column-name in the databasetable.
 
PHP PDO rowCount() Print E-mail
Thursday, 14 October 2010 14:57
PDOStatement->rowCount — Returns the number of rows affected by the last SQL statement
$resultset = $dbh->query($SQL); // PDO query code
$number_of_result_rows = $resultset->rowCount();
 
PHP Reguliar Expressions & UTF-8 Print E-mail
Thursday, 19 August 2010 09:50

The u modifier allows utf-8 encoded text to be properly matched.

Examples:

 

$match = preg_match('/[á]+/u', "tátátátá"); // result $match = 1

$amount = preg_match_all('/[á]+/u', "tátátátá", $matches); // result $amount = 4

 

More on regular expression modifiers:

http://php.net/manual/en/reference.pcre.pattern.modifiers.php

 
PHP PDO Print E-mail
Thursday, 19 August 2010 09:50
// PDO exception
// Database exception
set_exception_handler("PDOExeption");
function get_db()
{
// Open database
            return (open_PDO("db_name", "user", "pass")); 
}
function open_PDO($db_name, $user, $pass)
{
// Open Database met PDO class
    $dbh = new PDO("mysql:host=localhost;dbname=". $db_name, $user, $pass); 
// important - see code above: set_exception_handler 
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    return $dbh;
}
function PDOExeption($e)
{
    echo 'Caught exception: ',  $e->getMessage() , "\n";
}
 
 
PHP PDO open database Print E-mail
Thursday, 19 August 2010 09:50
// PDO open database
$dbh = get_db();
 
 
PHP PDO sluit database Print E-mail
Thursday, 19 August 2010 09:50
// PDO close database
$dbh = null;
 
 
PHP PDO UTF-8 Print E-mail
Thursday, 19 August 2010 09:50
// Open Database with the PDO class
    $dbh = new PDO("mysql:host=localhost;dbname=". $db_name, $user, $pass); 
    $resultset = $dbh->query("SET NAMES 'utf8'");
    $resultset = $dbh->query("SET CHARACTER SET utf8");
 
 
PHP PDO QUERY Print E-mail
Thursday, 19 August 2010 09:50
$resultset = $dbh->query($SQL); // PDO query code
 
 
PHP PDO FETCH Print E-mail
Thursday, 19 August 2010 09:50
while ($data = $resultset->fetch(PDO::FETCH_ASSOC)) // get data
{
    // Do something with the data
}
 
 


 

Mobielstartpagina.nl

Visit our mobile portal page:

http://www.mobielstartpagina.nl

or

http://www.mobielstartpagina.nl/iPhone

on your smartphone!

Tech news and updates by PCWorld. Focused on computers and consumer electronics, topics include computer hardware, software, wireless, digital entertainment, security and anti-virus and gadgets.