I recently tried to install or add the PHP mssql driver to connect with the ms sql server. Official compiled dll for the php_sqlsrv is until version 5.4, and does not support PHP version 5.5 and beyond.
I tried adding the extension, but XAMPP keeps on telling me there is something wrong. It gives a message like "startup: sqlsrv: unable to initialize module..". I searched the internet for some time, until I came across a solution on my particular problem.
It seems there is a need to compile a newer version of the php_sqlsrv driver. Thankfully someone did that for me since I certainly have no idea how to compile this source file. This is only for test purposes only, so hopefully the compiled dll does not have anything else besides the intended purpose of connecting to the ms sql server.
Here is the link to that file: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e1d37219-88a3-46b2-a421-73bfa33fe433/unofficial-php-55-drivers-x86
Website Development & Programming related to front-end and back-end. Tech news: on gadgets, technology for the web and other things I think will be of use to people to be on the know.
Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
Wednesday, August 27, 2014
Thursday, March 6, 2014
PHP include_once from parent folder not working in version 5 above
I don't know why but the include_once does not work if the file is one folder above the file calling it. There is a fatal error logged in the error log file, but it does seem to be still working.
The solution, that I found here: http://stackoverflow.com/questions/5588639/php-include-once-not-working
seems to work, and does not register as error after I place the code sample:
include_once (dirname(__FILE__) . '/../file.php');
The solution, that I found here: http://stackoverflow.com/questions/5588639/php-include-once-not-working
seems to work, and does not register as error after I place the code sample:
include_once (dirname(__FILE__) . '/../file.php');
Thank you, to the person who shared the answer.
Wednesday, December 11, 2013
DateTime functions not working in new set-up PHP 5.3.27 or any other version
You may seem to find yourself in a predicament when you have a new server with a default set-up of PHP configuration. When you transfer your working website when it does not work as intended.
I was searching on the web how can this be? Does the new version, not accommodate the functions used previously. You might assume that, but the simple solution to the problem is the Date Timezone settings in the config or PHP.ini file. You just need to set it to your desired timezone. Once you have specified this, the functions should work as it used to before.
At least that what solved my problem.
I was searching on the web how can this be? Does the new version, not accommodate the functions used previously. You might assume that, but the simple solution to the problem is the Date Timezone settings in the config or PHP.ini file. You just need to set it to your desired timezone. Once you have specified this, the functions should work as it used to before.
At least that what solved my problem.
Wednesday, December 4, 2013
PHP PDO why the error message given has the computer name, and domain
I have been trying to connect to mySQL server locally and there is an error give with Password:NO.
After searching for a while there is a simple explaination the username and password I have given does not have rights to the database I have specified, hence the error message.
The solution and explination can be found here: http://stackoverflow.com/questions/13002409/why-php-pdo-uses-a-different-from-hostname-to-the-one-used-by-mysql-connect-wh
Hope this helps. Happy coding.
After searching for a while there is a simple explaination the username and password I have given does not have rights to the database I have specified, hence the error message.
The solution and explination can be found here: http://stackoverflow.com/questions/13002409/why-php-pdo-uses-a-different-from-hostname-to-the-one-used-by-mysql-connect-wh
Hope this helps. Happy coding.
Monday, December 2, 2013
500 Internal Server Error Message
At work I have seen one of our site going down/offline and looking at it on the IIS the website is on and looking at the log files, there was no error.
I think this website could be the answer on why it has been down: https://kb.mediatemple.net/questions/1903/Why+am+I+getting+a+500+Internal+Server+Error+message%3F
Which is understandable, since out database is located somewhere else. It could have been timeout that causes our website to show 500 error.
Another thing that could help in determining is the Timeout detection as a sample on this website: http://bytes.com/topic/php/answers/620062-how-handle-php-execution-timeouts-gracefully
What I don't understand is why we cannot connect at times on Remote Desktop, though.
I think this website could be the answer on why it has been down: https://kb.mediatemple.net/questions/1903/Why+am+I+getting+a+500+Internal+Server+Error+message%3F
Which is understandable, since out database is located somewhere else. It could have been timeout that causes our website to show 500 error.
Another thing that could help in determining is the Timeout detection as a sample on this website: http://bytes.com/topic/php/answers/620062-how-handle-php-execution-timeouts-gracefully
What I don't understand is why we cannot connect at times on Remote Desktop, though.
Saturday, October 26, 2013
If conditional statement in a single line using Operators (?:)
I often forget how to do the simplified condition using the (?:) symbol. And it is very hard to search on what you meant to search at times. It's called the ternary operator logic (?:).
I found a source where it shows just how to do it in different levels of complexity:
http://davidwalsh.name/php-shorthand-if-else-ternary-operators
In case the site goes offline. The Ternary Logic is the process of using the following syntax: "(condition) ? (true value return) : (false value return)". This will shorten the if/else statement to a single line.
But often this technique confuses others not familiar with it. But it is fun way to do it. I still prefer the long way, but will use it to shorten the code at times.
based on the website source link, here is a sample:
I found a source where it shows just how to do it in different levels of complexity:
http://davidwalsh.name/php-shorthand-if-else-ternary-operators
In case the site goes offline. The Ternary Logic is the process of using the following syntax: "(condition) ? (true value return) : (false value return)". This will shorten the if/else statement to a single line.
But often this technique confuses others not familiar with it. But it is fun way to do it. I still prefer the long way, but will use it to shorten the code at times.
based on the website source link, here is a sample:
$var = 6;
$var_result = ($var>3 ? true:false); // it will return true
Wednesday, July 31, 2013
Email Validation on PHP
I have made email validation before, but have forgotten where I placed that code. I had to look for the RegEx (Regular Expression) around the net, there are some that work at a certain point, but does not if you had something like .com.ph or .com.us or .com.au.
There is also a question about the why the hyphen in his code does not work:
http://stackoverflow.com/questions/7939147/preg-match-email-validation-adding-hyphen-to-domain-spot
There is also this one that works, well almost (upper case letters not allowed on this one):
http://www.developphp.com/view_lesson.php?v=224
Explanations on how to add a hyphen to the Regular Expression:
http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
http://stackoverflow.com/questions/6744587/simple-regex-match-any-string-with-at-least-one-hyphen
So I tweak the code a bit to have the perfect email validation code I have seen so far, and here it is:
$email = "test@test-tester.com.ph" //<-- Works
$Syntax='/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/';
There is also a question about the why the hyphen in his code does not work:
http://stackoverflow.com/questions/7939147/preg-match-email-validation-adding-hyphen-to-domain-spot
There is also this one that works, well almost (upper case letters not allowed on this one):
http://www.developphp.com/view_lesson.php?v=224
Explanations on how to add a hyphen to the Regular Expression:
http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
http://stackoverflow.com/questions/6744587/simple-regex-match-any-string-with-at-least-one-hyphen
So I tweak the code a bit to have the perfect email validation code I have seen so far, and here it is:
$email = "test@test-tester.com.ph" //<-- Works
$Syntax='/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/';
if (preg_match($Syntax, $email)) {
echo $email . \" is a valid email. We can accept it.\";
} else {
echo $email . \" is an invalid email. Please try again.\";
}
Let me know if there is an improvement for this code.
Also a bit of caveat on the preg_match() function:
preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred
as mentioned in PHP documentation:
Tuesday, July 9, 2013
Cookie Setting troubles in PHP
I was trying to determine why the value for a cookie is not reflecting on my page.
Here are some of other developers say you should now in implementing cookies:
There is a problem with the cookie when the mobile browser is never closed. I had my browser open in the background. Even when I set the cookie to expire in 30 mins. It does not happened, since the browser still reads the value even beyond expire date.
Here are some of other developers say you should now in implementing cookies:
- It has to be on top before any code is generated by the page
- Cookie will not reflect on the same page when you set it. It will reflect on the next loading of the page.
2nd one is true. The first one also seems to be true, since no value is placed when I placed the code in the middle and after html codes have been rendered.
Here are the links to those recommendations:
There is a problem with the cookie when the mobile browser is never closed. I had my browser open in the background. Even when I set the cookie to expire in 30 mins. It does not happened, since the browser still reads the value even beyond expire date.
Wednesday, June 19, 2013
Notepad++ free IDE for programming
I just started using this IDE called notepad++. I have been hearing things about this app, and when I tried it, I had a bit of a hard time getting the hang of it.
The only thing I liked about it. Is the document preview on the right side, where I can see the whole code and drag the view to where I want to be. There could be more features on this free IDE, I could just be scratching the surface.
As a free tool, I like this IDE already. Only thing lacking, is the design window, but that could be asking for something else, when it is just an advance version of notepad.
Official website of Notepad++: http://notepad-plus-plus.org/
The only thing I liked about it. Is the document preview on the right side, where I can see the whole code and drag the view to where I want to be. There could be more features on this free IDE, I could just be scratching the surface.
As a free tool, I like this IDE already. Only thing lacking, is the design window, but that could be asking for something else, when it is just an advance version of notepad.
Official website of Notepad++: http://notepad-plus-plus.org/
Wednesday, May 15, 2013
jQuery Thickbox, passing querystring value
I found a solution for passing value using the jQuery Thickbox. My error was I placed the querystring value at the end, when I should have placed it on the front.
Sample:
page.php?queryvar=a&TB_iframe=true
This solved my problem. Thank you internet for giving the answer, but the answer was deep in the haystack.
Sample:
page.php?queryvar=a&TB_iframe=true
This solved my problem. Thank you internet for giving the answer, but the answer was deep in the haystack.
Labels:
javascript,
jQuery,
Philippines,
PHP,
Programming,
thickbox
Monday, March 4, 2013
I often relay on the javascript, when it can be done on plain html and server side script
I have been guilty of using excessive javascript on my website developments, while ignoring the fact that some people, especially the iOS device users at time disable their javascript on their browsers.
I have been developing my own version of captcha, and I designed it, by using an external javascript, that in a way no one will be able to see the generated script on the page itself.
Only problem, is the method I created is not compatible with old iPad devices that have not updated their safari browser. I was able to fix the problem, by directly placing the images on the page and not changing values on my html elements.
I have been developing my own version of captcha, and I designed it, by using an external javascript, that in a way no one will be able to see the generated script on the page itself.
Only problem, is the method I created is not compatible with old iPad devices that have not updated their safari browser. I was able to fix the problem, by directly placing the images on the page and not changing values on my html elements.
Wednesday, December 26, 2012
Free Mobile Browser Detection code generation
While searching for a mobile browser detection code, I came across this site: http://detectmobilebrowsers.com/
This site generates the code for popular browsers to detect using the USER AGENT of the browser used. It's free to use, and donation to keep the site alive is pretty much appreciated by the author.
This is another useful website, that is simple to use, but takes a while to dissect the code. You pretty much need to brush up on your regular expression to understand the code and what it compares. But if you are not worried about the code behind the detection, by all means, just paste the code to your site and set the redirection page.
This site generates the code for popular browsers to detect using the USER AGENT of the browser used. It's free to use, and donation to keep the site alive is pretty much appreciated by the author.
This is another useful website, that is simple to use, but takes a while to dissect the code. You pretty much need to brush up on your regular expression to understand the code and what it compares. But if you are not worried about the code behind the detection, by all means, just paste the code to your site and set the redirection page.
Tuesday, June 5, 2012
Quirks mode in IE browser
It has been a problem for developers to have all browsers display their content as they intended it to be. But, often, challenges are the different browser rendering, and different versions of the browsers doing something else.
The Quirks mode was made for the browser to render a specific page that it thinks isn't created for current html standard. Often, this is to accommodate the old webpages that have not been updated to current new standard of the W3C specifications.
If you have been trying to create a webpage and the browser often resort to rendering it in Quirks Mode, it is better if you specify the doc type. It isn't the best solution, but it will tell the browser to present the document or webpage the way you want it to be.
Use the following code on the very top of your page to have it render correctly as you intended it to be:
The sources, I used to have the solution are on the following websites:
http://hsivonen.iki.fi/doctype/
The Quirks mode was made for the browser to render a specific page that it thinks isn't created for current html standard. Often, this is to accommodate the old webpages that have not been updated to current new standard of the W3C specifications.
If you have been trying to create a webpage and the browser often resort to rendering it in Quirks Mode, it is better if you specify the doc type. It isn't the best solution, but it will tell the browser to present the document or webpage the way you want it to be.
Use the following code on the very top of your page to have it render correctly as you intended it to be:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">The sources, I used to have the solution are on the following websites:
http://hsivonen.iki.fi/doctype/
http://www.quirksmode.org/css/quirksmode.html
Thursday, March 8, 2012
Passing values or reference example in PHP
Note: The code and principles are not mine, I only reposted them from php.net website.
I like this example, very easy to follow on passing reference and value:
<?php
//The two are meant to be the same
$a = "Clark Kent"; //a==Clark Kent
$b = &$a; //The two will now share the same fate.
$b="Superman"; // $a=="Superman" too.
echo $a;
echo $a="Clark Kent"; // $b=="Clark Kent" too.
unset($b); // $b divorced from $a$b="Bizarro";
echo $a; // $a=="Clark Kent" still, since $b is a free agent pointer now.
//The two are NOT meant to be the same.
$c="King";
$d="Pretender to the Throne";
echo $c."\n"; // $c=="King"
echo $d."\n"; // $d=="Pretender to the Throne"
swapByValue($c, $d);
echo $c."\n"; // $c=="King"
echo $d."\n"; // $d=="Pretender to the Throne"
swapByRef($c, $d);
echo $c."\n"; // $c=="Pretender to the Throne"
echo $d."\n"; // $d=="King"
function swapByValue($x, $y){
$temp=$x;
$x=$y;
$y=$temp;
//All this beautiful work will disappear
//because it was done on COPIES of pointers.
//The originals pointers still point as they did.
}
function swapByRef(&$x, &$y){
$temp=$x;
$x=$y;
$y=$temp;
//Note the parameter list: now we switched 'em REAL good.
}
?>
First principle:
A pointer stores a memory address to access an object. Any time an object is assigned, a pointer is generated. (I haven't delved TOO deeply into the Zend engine yet, but as far as I can see, this applies)
2nd principle, and source of the most confusion:
Passing a variable to a function is done by default as a value pass, ie, you are working with a copy. "But objects are passed by reference!" A common misconception both here and in the Java world. I never said a copy OF WHAT. The default passing is done by value. Always. WHAT is being copied and passed, however, is the pointer. When using the "->", you will of course be accessing the same internals as the original variable in the caller function. Just using "=" will only play with copies.
3rd principle:
"&" automatically and permanently sets another variable name/pointer to the same memory address as something else until you decouple them. It is correct to use the term "alias" here. Think of it as joining two pointers at the hip until forcibly separated with "unset()". This functionality exists both in the same scope and when an argument is passed to a function. Often the passed argument is called a "reference," due to certain distinctions between "passing by value" and "passing by reference" that were clearer in C and C++.
Just remember: pointers to objects, not objects themselves, are passed to functions. These pointers are COPIES of the original unless you use "&" in your parameter list to actually pass the originals. Only when you dig into the internals of an object will the originals change.
Original document or forum can be found here somewhere:
http://php.net/manual/en/language.oop5.references.php
I like this example, very easy to follow on passing reference and value:
<?php
//The two are meant to be the same
$a = "Clark Kent"; //a==Clark Kent
$b = &$a; //The two will now share the same fate.
$b="Superman"; // $a=="Superman" too.
echo $a;
echo $a="Clark Kent"; // $b=="Clark Kent" too.
unset($b); // $b divorced from $a$b="Bizarro";
echo $a; // $a=="Clark Kent" still, since $b is a free agent pointer now.
//The two are NOT meant to be the same.
$c="King";
$d="Pretender to the Throne";
echo $c."\n"; // $c=="King"
echo $d."\n"; // $d=="Pretender to the Throne"
swapByValue($c, $d);
echo $c."\n"; // $c=="King"
echo $d."\n"; // $d=="Pretender to the Throne"
swapByRef($c, $d);
echo $c."\n"; // $c=="Pretender to the Throne"
echo $d."\n"; // $d=="King"
function swapByValue($x, $y){
$temp=$x;
$x=$y;
$y=$temp;
//All this beautiful work will disappear
//because it was done on COPIES of pointers.
//The originals pointers still point as they did.
}
function swapByRef(&$x, &$y){
$temp=$x;
$x=$y;
$y=$temp;
//Note the parameter list: now we switched 'em REAL good.
}
?>
First principle:
A pointer stores a memory address to access an object. Any time an object is assigned, a pointer is generated. (I haven't delved TOO deeply into the Zend engine yet, but as far as I can see, this applies)
2nd principle, and source of the most confusion:
Passing a variable to a function is done by default as a value pass, ie, you are working with a copy. "But objects are passed by reference!" A common misconception both here and in the Java world. I never said a copy OF WHAT. The default passing is done by value. Always. WHAT is being copied and passed, however, is the pointer. When using the "->", you will of course be accessing the same internals as the original variable in the caller function. Just using "=" will only play with copies.
3rd principle:
"&" automatically and permanently sets another variable name/pointer to the same memory address as something else until you decouple them. It is correct to use the term "alias" here. Think of it as joining two pointers at the hip until forcibly separated with "unset()". This functionality exists both in the same scope and when an argument is passed to a function. Often the passed argument is called a "reference," due to certain distinctions between "passing by value" and "passing by reference" that were clearer in C and C++.
Just remember: pointers to objects, not objects themselves, are passed to functions. These pointers are COPIES of the original unless you use "&" in your parameter list to actually pass the originals. Only when you dig into the internals of an object will the originals change.
Original document or forum can be found here somewhere:
http://php.net/manual/en/language.oop5.references.php
Subscribe to:
Posts (Atom)