Parse Error : Invalid Numeric Literal in Laravel - php

I have get following error in my Laravel Application.
Turns out that the error points to the following lines:
/* August */
$augledcrdt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',08)->where('company_id',$companyids)->sum('credit_amt');
$augleddebt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',08)->where('company_id',$companyids)->sum('debit_amt');
/* September */
$sepledcrdt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',09)->where('company_id',$companyids)->sum('credit_amt');
$sepleddebt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',09)->where('company_id',$companyids)->sum('debit_amt');

I think you are using PHP 7.0. You can use the following piece of code to do so:
$augledcrdt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date','08')->where('company_id',$companyids)->sum('credit_amt');
$augleddebt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date','08')->where('company_id',$companyids)->sum('debit_amt');

You should change 08 to 8 if you're using PHP7:
->whereMonth('transaction_date', 8)
http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.integers

Related

PHP PDO Incorrect syntax near GO, MSSQL & sql_srv [duplicate]

This question already has answers here:
Incorrect syntax near 'GO'
(9 answers)
Closed 6 years ago.
I am having trouble executing a long MSSQL script using PHP and PDO.
It contains some batch statements separated by GO. The script runs if its executed in Management Studio.
I have ensured line endings are not causing the issue.
I have also tried to enable beginTransaction() before the request is executed. Which returns the following error: SQLSTATE[IMSSP]: This function is not implemented by this driver.
I'm using IIS8 and PHP 5.4.16 and the pdo_sqlsrv driver
First part of the script:
USE foo;
IF object_id(N'ToBit', N'FN') IS NOT NULL
DROP Function dbo.ToBit
GO
CREATE FUNCTION dbo.ToBit(
#InputString varchar(250)
)
RETURNS BIT
AS BEGIN
DECLARE #OutputBit BIT
SET #OutputBit = CASE
WHEN (#InputString = 'yes') THEN 1
WHEN (#InputString = 'true') THEN 1
WHEN (#InputString = '1') THEN 1
ELSE 0
END
RETURN #OutputBit
END
Is it down to the driver? I can't see why GO would require beginTransaction() being called? Other than that I'm out of ideas.
Update: I think I might have found an answer here. Will update if I find a soloutio.
Incorrect syntax near 'GO'
Have found an answer here by Jon Galloway
GO isnt valid T-SQL, its a command used by SQLCMD and other utilities, and parsed before execution.
It looks like there are a few options.
1) Execute the script using OSQL / command line
2) Split the script at each GO separator, then run them in sequence
3) If using .NET you can look at using SQL Server Management Objects:
Server.ConnectionContext.ExecuteNonQuery()
This parsers T-SQL statements and "gets" the GO statement as a batch separator.

CBOR implementation produces error on PHP 5.3.3

I am using CBOR for packing data in my C applications and PHP scripts. For PHP, I've downloaded implementation from the site above. It works good at PHP 5.4.23, but on PHP 5.3.3 including CBOREncoder.php produces an error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/html1/......./CBOREncoder.php on line 15
This is beginning of CBOREncoder.php:
<?php
/**
* CBOR encoder/decoder
*
* http://tools.ietf.org/html/rfc7049
* http://habrahabr.ru/post/208690/ thx man :)
*
* Class CBOREncoder
*/
class CBOREncoder
{
const
MAJOR_OFFSET = 5,
HEADER_WIPE = 0b00011111, <-- this line produces error
ADDITIONAL_WIPE = 0b11100000,
What's the problem?
The problem is PHP 5.3.x does not support binary numbers. That was included in PHP 5.4.
From php website: http://php.net/manual/en/migration54.new-features.php
Binary number format has been added, e.g. 0b001001101.
So, CBOR does not support PHP 5.3

strtotime compatibility

Ok this relates to another question I have asked but as I have now pinpointed
the issue I thought it would be clearer on a new question.
The problem I am having relates to strtotime under PHP 4.4
I have a larger script that is failing under PHP 4.4 but works under PHP 5+
To check it was this I wrote the following and copied it to two servers one
running PHP 4.4 and the other PHP 5.3.
<?php
$my_time = '2013-03-18T21:38:58.000Z';
$my_time = strtotime($my_time);
echo $my_time;
?>
The output under PHP 4.4 was: -1
The output under PHP 5.3 was: 1363642738
Is there a way to get the same result under PHP 4.4 as 5.3??
Thanks in advance for any help!
-1 was the failure code for PHP < 5.1. This makes me think that PHP 4 can't parse that string.
This means you'll have to use a format both versions support. As a hack, you could do some string manipulation. If you can change the format of the string though, that's your best route. (Actually, your best route is to run the hell away from PHP 4.)
I don't have an installation of PHP 4 to test with, but try removing the .000Z from the end, all the examples on the strtotime page on PHP.net don't have that bit PHP 4.4 may not support it.
If that works ultimately you can parse any time stamps with a substr($my_time, 0, 19)

Php microseconds in relative templates

I have a date time object which I would like to modify the microseconds. I'm using the following code.
$datesArray[$alreadyDoneIndices+$countIndices]->modify("+$microsecondIncrementAmount mseconds");
and I'm getting the following error message.
DateTime::modify() [datetime.modify]: Failed to parse time string (+38462 microseconds) at position 3 (4): Unexpected character in C:\xampp\htdocs\DynamicUpdating\timelineUpdater.php on line 147
What's not working with this? Is there a reference for what relative timestamps work in php that I'm missing if that is the problem?
Just check mseconds in modify("+$microsecondIncrementAmount mseconds") The error message tells you that the time string is wrong.
$datesArray[$alreadyDoneIndices+$countIndices]->modify("+{$microsecondIncrementAmount} mseconds");
Notice the {}

Which PHP version is required for str_split?

I relogin to my server in dreamhost and test some scripts.And I found I couldn't use str_split. Message of Undefined function was given.I checked the version in the server and its PHP Version is 5.2.12.And I just wonder which version is required?Thanks.
Testcode:
<?php
$arr = str_split("lsdjflsdjflsdjflsdjfl");
print_r($arr);
?>
Message:
Fatal error: Call to undefined function: str_split() in /test.php on line 3
Edit #Justin Johnson
I checked the server's system directory,and I found there are two versions of PHP in Dreamhost.In user's webroot,file will be parsed by PHP5 and that's why I got php 5.2.12 by putting a phpinfo.php in the webroot.And if php files are ran in command line directly using php test.php,another php version which is 4.x worked.That's the reason I got an error.When I use
/usr/local/php5/bin/php test.php
Everything is fine.
Rather than use str_split, it's usually much easier to iterate through the characters of the string directly:
$s="abc";
$i=0;
while(isset($s[$i])) {
echo $s[$i++]." ";
}
see?
First off: The PHP documentation will always say what version is required for every function on that function's documentation page directly under the function name.
It is possible that an .htaccess file is somewhere in your path and is causing a previous version (<5) of PHP to be used. To double (or triple) check to make sure that you are running in the proper PHP version, place this code above the line where you call str_split
echo "version:", phpversion(),
"<br/>\nstr_split exists? ",
function_exists("str_split") ? "true" : "false";
However, as shown by Col. Shrapnel, it is not necessary to convert a string to an array of individual characters in order to iterate over the characters of that string. Strings can also be iterated over using traditional iteration methods, thus making the call to str_split unnecessary and wasteful (unless you need to segment the string into fixed length chunks, e.g.: str_split($s, 3))
foreach ( str_split($s) as $c ) {
// do something with character $c
}
can be replaced by
$s = "lsdjflsdjflsdjflsdjfl";
for ( $i=0; isset($s[$i]); ++$i ) {
// do something with character $s[$i]." ";
}
which is equally, if not more clear.
According to dreamhost wiki, you need to switch to php5 manually from control panel, if you created your domain before 2008 sept.
http://wiki.dreamhost.com/Installing_PHP5#Using_DreamHost.27s_PHP_5
PHP 5 was added to all plans by
DreamHost as of June 2005. As of
September 2008, support for PHP4 was
discontinued, so you can no longer
switch back to PHP 4 from PHP 5 from
the panel.
If you haven't switched to PHP 5 yet,
you can do this in the Control Panel.
But, again, you will not be able to
switch back to PHP 4 after switching
to PHP 5.
Here's how to switch from PHP 4 to PHP
5:
Log into the DreamHost Control Panel.
Click Domains, then Manage Domains.
Click the wrench icon next to the domain you want to activate PHP 5
on (under the Web Hosting column).
Select PHP 5.x.x from the dropdown menu.
Click Change fully hosted settings now! at the bottom of the
section.
Repeat steps 3-5 for each additional domain you want to
activate.
you could also check your php version with
<?php
phpinfo();
?>
The version required is PHP 5 or later. So theoretically your program should work.
If you can't get str_split to work, just use a string as an array:
$stuff = "abcdefghijkl";
echo $stuff[3];
will produce
d
This method is fastest, anyway. I don't know if it suits your needs, but if it does, I hope it helps!
Could be anything in your code. How do we know its not a 10 line script or 2000 line script?
You can use preg_split() to split an array into single characters, but it will return an extra empty string at the begining and the end.
$a = preg_split("//","abcdefg");
echo json_encode($a);
prints:
["","a","b","c","d","e","f","g",""]

Categories