PHP - Convert Sql Server Timestamp (ts) Binary To String?
I'm hitting a SQL Server db and every table has a ts (timestamp) field that is a binary datatype - 8 bytes. Is there a way to "read" the binary and output it as a string?
Similar TutorialsI'm planning on storing RIPEMD-160 passphrase hash's raw binary data in MySQL as BINARY(20). Right now, I'm not sure if one of the following INSERT approach is more preferrable and more efficient: Approach (1) - Using mysqli::real_escape_string() ================================================= Code: [Select] $binhash = $mysqli->real_escape_string(hash('ripemd160', $passphrase, true)); $mysqli->query("INSERT INTO testtbl (Passphrase) VALUES ('" . $binhash . "')"); This approach saves hash() from converting raw binary data to hexadecimal format, but need to process and escape the binary string. Approach (2) - Using UNHEX() on MySQL ===================================== Code: [Select] $hexhash = hash('ripemd160', $passphrase); $mysqli->query("INSERT INTO testtbl (Passphrase) values (UNHEX('" . $hexhash . "'))"); This approach needs hash() to convert binary data to hexadecimal but no need for escaping the string and it put extra load on MySQL to convert the hexadecimal back to binary. Hi there. I was wondering if it were possible to convert text to numbers or some sort of URL friendly link. For example, "Hello there" would be converted to '435342553' or whatever. I want to do this because for example when someone goes to this URL, example.com/435343434, the number/uri string would be decoded and whatever the text was it would be displayed on the site. I can write all this code no bother I just need some advice/ideas on the the encoding/decoding of the text. I was looking at some options for doing this..... hexdec - removes spaces md5 - cannot be decoded? None of them seem to be working, the problem is decoding them. md5 creates a perfect uri string but as I said it cannot be decoded. I would appreciate any ideas of suggestions. Thanks a million. Ok Let's say I have a timestamp: 1327482941 I want to convert this to output only "60" im not looking for a whole time_ago function, simply just need to convert a timestamp down to seconds ONLY not having minutes/years/etc no need none of that just purely seconds starting from 1-60 if so how is it possible? I tried to just Code: [Select] $seconds = substr($e,1,4) . ""; $e is my timestamp, I did this because I could just grab the last 2 digits in the timestamp that would be what I want, but that's not possible because it goes 1-90 not 1-60 ^_^ help Here is a code I am trying to make it only spit out 1-60 in seconds Code: [Select] function timeAgo4($timestamp, $granularity=1){ $difference = $timestamp; if($difference < 0) return '0'; elseif($difference < 86400){ $periods = array(60,'' => 1); $output = ''; foreach($periods as $key => $value){ if($difference >= $value){ $time = round($difference / $value); $difference %= $value; $output .= ($output ? ' ' : '').$time.' '; $granularity--; } if($granularity == 0) break; } return ($output ? $output : '0').''; } else return date($format, $timestamp); } Can anyone please tell me how I convert DD-MM-YYY (text) to TIME (unix) thought I'd say that I have this line at the top of all my pages, just in case it means a different code. Code: [Select] date_default_timezone_set('Europe/London'); //### Set the default timezone sorry, I know this is simple, but stuck on it... how would one go about converting 1/21/11 to a UNIX timestamp, something like 1293035229? and while we are at it, how to convert 1293035229 to 1/21/11 ? (i know the timestamp is wrong, just for example) thanks!!!!! I have a string in php: Quote Sat, 28 Apr 2012 05:09:45 GMT I want to convert it to timestamp Example: 1335594473 Hi I have members DOB stored in a mysql table field called birthday in the following format YYYY-MM-DD I can't seem to convert the time stamp into the members age I need to be able to feed $birthday which is the field in mysql table that is in the above format and then use php code to convert to members age Everything I try doesn't seem to work
<?php $srs = array(); for ($section = 1; $section < 5; $section++) { for ($row = $section; $row < 10; $row++) { for ($seat = $row; $seat < 20; $seat++) { $srs[] = array( 'section_name' => $section, 'row_name' => $row, 'seat_name' => $seat); } } } output(convert_array($srs)); // Converts the array function convert_array($input) { return $input; } function output($obj) { echo "<pre>"; print_r($obj); echo "</pre>"; die; } ?>
I'm trying to convert those array number to string, add implode() to make it happen, but seem PHP didn't recognize variable in $input. Like this implode("Section: ", $input) or (Section: ", $srs). Can you help me? Thanks, Gary Edited October 16, 2019 by sigmahokiesI have a form that submits G How can I convert this to string of time when I need to insert it into the database and then turn it back around when it needs to be read? <option>11:00 AM</option> <option>11:30 AM</option> <option>12:00 PM</option> <option>12:30 PM</option> <option>1:00 PM</option> <option>1:30 PM</option> Thank you. //$value1 = $_POST['game']; $value1 = "game7h"; if (strpos($value1, 'a')) { $team = 'a'; }elseif (strpos($value1, 'h')) { $team = 'h'; } if (strpos($value1, '7')) { $num = '7'; } elseif (strpos($value1, '8')) { $num = '8'; } elseif (strpos($value1, '9')) { $num = '9'; } $gm7hodds = $games[41]["BP"]; $gm7aodds = $games[40]["BP"]; $gm8hodds = $games[47]["BP"]; $gm8aodds = $games[46]["BP"]; $gm9hodds = $games[53]["BP"]; $gm9aodds = $games[52]["BP"]; /* $getratio = $num + $team; echo $getratio; Team is not a math operation so I'll finesse that later. */ $findratio = 'gm' . $num . 'h' . 'odds'; echo $findratio; gm7hodds How would I add the $ to it and return its array value $gm7hodds? Solved whoops -> echo eval('return $'. $findratio. ';'); Edited April 28 by Minzersolved Hi everybody, I need some help about how to convert string to array name. I have the following function which pass $_REQUEST type as parameter. It is not working because I don't know how to convert $method to $_GET or $_POST in a proper way. Do anybody know how? Code: [Select] function validateIfFilled($method, $fields) { $exploded=explode(",",$fields); foreach($exploded as $field){ if(empty($method[trim($field)])){ return false; } } return true; }; if(!validateIfFilled('$_GET', "email, password, address")) ... Thank you! how can i convert string type into integer like when using parseInt in javascript...however i use (int)$string but not working i have this $string1="10"; $string2="5"; and i wish to add both string ....using (int) still treat $string1 and $string2 as string so i get 105 as a result instead of 15 Code: [Select] <?php $myServer = "202.138.125.155"; $myUser = "micro_fms"; $myPass = "micro_fms*#$"; $myDB = "micro_fms"; //create an instance of the ADO connection object $conn = new COM("ADODB.Connection")or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER='SQLOLEDB'; SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; //Open the connection to the database $conn->open($connStr); //$table_name=$_GET['Device']; $table_data=$_GET['Data']; $data=(explode(",",$table_data)); $table_name=$data[0]; $speed=$data[1]; $time=$data[2]; $date=$data[3]; $lat=$data[4]; $long=$data[5]; //$newdate = substr($date,6,2) . "-" . substr($date,0,2) . "-" substr($date,3,2); $datetime=$date.$time; $new_lat = substr($lat,0,2).'.'.substr($lat,2); $new_long = substr($long,0,2).'.'.substr($long,2); echo $table_name."<br>"; echo $speed."<br>"; echo $new_lat."<br>"; echo $new_long."<br>"; echo $datetime."<br>"; $query="insert into $table_name (DeviceNumber,Speed,dtDateTime,Latitude,Longitude)values('$table_name','$speed','$datetime','$new_lat','$new_long')"; //execute the SQL statement and return records $rs = $conn->execute($query); if($rs) { echo 'Values Inserted'; } else { echo "faile"; } ?> Hi friends... I have two variables ($date and $time). I concat these two strings and make a new variable called "$datetime". Now in above code I want to insert it into table but I got the following error. Code: [Select] Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for SQL Server<br/><b>Description:</b> Conversion failed when converting datetime from character string.' in C:\wamp\www\FMS\fms.php:44 Stack trace: #0 C:\wamp\www\FMS\fms.php(44): com->execute('insert into A00...') #1 {main} thrown in C:\wamp\www\FMS\fms.php on line 44 In my database, data type of column in which I want to insert is Date time stamp though I have string type ($datetime) variable. I think I have to convert this $datetime variable string to "DateTime type first but don't have any idea about it. Please help??/ Thanks in advance.... I got a response from an api in json. How do i echo out the account_name in string. Thanks as usual. The response is below...
{ "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } } "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } }
I have ip_addresses stored in the database as unsigned integers. I want to display them in standard xxx.xxx.xxx.xxx format in a table. In my code, I tried the following: <?php while ($row = $query->fetch()) { $address = inet_ntoa($row['IP_ADDRESS']); //Throws error here echo "<tr>"; // echo "<td>" . $row['IP_ADDRESS'] ."</td>"; echo "<td>" . $row['$address'] ."</td>"; echo "<td>" . $row['FILENAME'] ."</td>"; echo "<td>" . $row['country'] . "</td>"; echo "<td>" . $row['area'] . "</td>"; echo "<td>" . $row['city'] . "</td>"; echo "</tr>"; } ?> It throws the following error: Parse error: syntax error, unexpected 'inet_ntoa' (T_STRING) in /home/larry/web/test/public_html/report1.php on line 205 How do I do the conversion so I can display the ip_address? Thanks in advance, Larry
Hi, Sorry, me again! Ok, so i've got my url: http://www.mydomain.com/?ec3_after=2010-08-01&ec3_before=2010-08-07 I've then got the following code to get the values: $afterDateParts = split("-", $_GET['ec3_after']); $after = $afterDateParts[2] . " " . $afterDateParts[1] . " " . $afterDateParts[0]; echo $after; which returns: 01 08 2010 (correct for this demo) I've then got this to convert the above into a nicer format: $convertMe = strtotime($after); echo date('d-M-Y', $convertMe); But it always returns: 01 Jan 1970 For the love of god, I cannot work out why. Is it really not that simple? Please someone put me out my misery. I'm loosing hair by the minute! Lol TIA I have a simple form and need to convert it to XML so I can send it to my payment gateway. I have the XML data types (?) they are expecting, but do not have a clue of how to build the string. Can someone help me out? Thanks, Debbie How can i convert an array of results to a single comma separated string so that I can run it through an SQL query? Hello, i have the code below and i need to have all results in a variable as a string, inside the loop they are displayed how i want but outside will echo the last result. Thank You. Code: [Select] foreach($_POST as $key=>$value){ if (is_numeric($value)) { $valoare = "$value,"; } } echo $valoare; Well the topic may not sound very explicit. So I'll do my best to explain it here. I have a pull down menu as part of a form, which contains the months of the year. I'm trying to store the value of this form entry using the $_POST['month'] variable into a database but first, I need to convert the month values into their corresponding integer values( that is 1 for January, 2 for February etc), in order to easily do date calculations later down the road. Any ideas about how to do this? It may be helpful to include the code for the pull down menu. Code: [Select] <p><tab> Date of Birth: <?php //Make the month pull down menu. //Array to store months. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); print '<select name= "month">'; foreach ($months as $key => $value) { print "\n<option value=\"$key\">$value</option>"; } print '</select>'; ?> </tab> <tab> <?php //Make the day pull down menu print '<select name= "day">'; for ($day = 1; $day <= 31; $day++) { print "\n<option value=\"$day\">$day</option>"; } print '</select>'; ?> </tab> <tab><?php //Make the year pull down menu print '<select name= "year">'; $start_year = date('Y'); for ($y = ($start_year - 18); $y >= 1900; $y--) { print "\n<option value=\"$y\">$y</option>"; } print '</select>'; ?> </tab> </p> |