What the question title says. With a query such as SELECT @@IDENTITY AS ins_id
, do I need to supply the table name or any other info to specify which table/database i'm talking about?
Answers
Subtract the past most one from the future most one and divide by 60.
Times are done in Unix format so they're just a big number showing the number of seconds from January 1, 1970, 00:00:00 GMT
The problem is definitely with the Microsoft ODBC drivers version 11, and are fixed in ODBC Driver 13 Preview for SQL Server.
I discovered this as my development machine running ubuntu 14.04 with the Driver 13 Preview installed works fine, but then when I deployed to our production server running RHEL 7 with the Driver 11, all kinds of havoc ensued as column names were truncated at 15 chars.
Microsoft's documentation is lackluster for Linux support, so if you're running ubuntu, then here's the gist of getting it installed.
I got it figured out. I had to install the ODBC Driver 17 for SQL Server (msodbcsql_17.2.0.1_x64.msi) on my server. The SQL Server Native Client 11.0 was installed but not the ODBC Driver for SQL Server.
For future reference for anyone else with this or a similar issue...
It can be downloaded at https://www.microsoft.com/en-us/download/details.aspx?id=56567 (note: if you have a 32 bit server, you will want to install the msodbcsql_17.2.0.1_x86.msi - If you accidentally try to install the incorrect version, it will let you know during the installation). After the driver is installed, you need to reboot the server. It won't prompt you to restart, but you'll need to.
In my PHP.ini I have added extension=php_pdo_sqlsrv_72_nts.dll
and extension=php_sqlsrv_72_nts_x64.dll
They can be downloaded at https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017
More info can be found at https://docs.microsoft.com/en-us/sql/connect/php/loading-the-php-sql-driver?view=sql-server-2017 and https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017
I can now establish a connection to Sql Server using either sqlsrv_connect or PDO.
PDO connection test:
$SqlServer = "THISSERVERSQLEXPRESS";
$SqlServerCon = new PDO("sqlsrv:server=$SqlServer;Database=TheDatabase", "DbUName", "DbPassword");
if (!$SqlServerCon) {die('Unable To Connect to Sql Server');}
else
{echo "Connection Successful";}
sqlsrv_connect connection test:
$SqlServer = "THISSERVERSQLEXPRESS";
$DbConnInfo = array( "Database"=>"TheDatabase", "UID"=>"DbUName", "PWD"=>"DbPassword");
$SqlServerCon = sqlsrv_connect( $SqlServer, $DbConnInfo);
if( $SqlServerCon ) {echo "Connection established";}
else
{echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));}
EDIT:
This issue isn't necessarily specific to the goal you try to achieve.
Although, there definitely is a bug in our 1.0.6 wrapper.
In the wrapper code, we use the 4th parameter of the json_decode()
function, which was only introduced in PHP 5.4 (See the "Changelog" section here).
Two ways you can solve this:
- Either update your system's PHP version to >= 5.4
- Or (until we introduce a fix on our side), modify the wrapper locally to not use that option (see here), which very well might bring new issues and isn't the recommended fix.
Hope this helped. We certainly are grateful that this brought that particular issue to our attention :)
Edit2:
To clarify, here's what the second approach means in term of code:
$this->_response = json_decode($buffer, false, 512, JSON_BIGINT_AS_STRING);
//Becomes
$this->_response = json_decode($buffer, false, 512);
That should eliminate the warning and solve the issue. Isn't that great?! ;-)
As I really am not able to reproduce your issue on my end, here is a question:
Is the contact you are trying to create listed in the response when you issue the following code ?
Alternatively, go here for a list of your account's contacts.
$mj = new Mailjet($apiKey, $secretKey);
$contact = $mj->contact();
var_dump($contact);
If it is, this is why what I wrote in my response on your other question doesn't work.
But why?
Well, you are trying to create a contact that is already listed in your account. The process of creating a contact doesn't necessarily mean that it has to be assigned to a contacts list.
The fix
Either get the existing contact's id instead of creating it before adding it to a list:
$mj = new Mailjet($apiKey, $secretKey);
$viewContact = [
"method" => "VIEW",
"unique" => "gaetan.philippot@gmail.com"
];
$contact = $mj->contact($viewContact);
echo "Contact ID: ".$contact->Data[0]->ID."n";
// Then proceed as described in my original answer.
Or delete it through the web interface and try following my answer again.
(Click on the contact's email, then click on the yellow menu next to its avatar and click on remove.)
Does that solve your issue? :-)
@@IDENTITY
returns the most recent identity generated in the current session. In most cases you'll probably want to useSCOPE_IDENTITY
instead, which returns the most recent identity generated in the current scope.For example, if you insert a row into table1, but that insert fires a trigger which inserts a row into table2, then
@@IDENTITY
will return the identity from table2 whereasSCOPE_IDENTITY
will return the identity from table1.